(function(window) {
	
	var today = new Date();
	var form;
	var monthNames = [ null, "January", "February", "March", "April", "May",
			"June", "July", "August", "September", "October", "November",
			"December" ];
	var selects = [];

	function DateAndTimeDropDowns(pContainer, pFormID){
		form = document.createElement("FORM");
		form.id = pFormID
		pContainer.appendChild(form);
		createDaysDropDown();
		createMonthsDropDown();
		createYearsDropDown();
		createHoursDropDown();
		createMinutesDropDown();
		createGoButton();
		createNowButton();
	}
		
	createDaysDropDown = function() {
		var selectElement = document.createElement("SELECT");
		selectElement.name = "day";
		selectElement.id = "day";
		var t;
		for ( var i = 1; i < 32; ++i) {
			var dateText = i;
			if (dateText < 10)
				dateText = "0" + dateText;
			t = new Option(i, dateText);
			selectElement.options.add(t);
		}
		selectElement.selectedIndex = today.getDate() - 1;
		selects.push(selectElement);
		form.appendChild(selectElement);
	}
	createMonthsDropDown = function() {
		var selectElement = document.createElement("SELECT");
		selectElement.name = "month";
		selectElement.id = "month";
		var t;
		for ( var i = 0; i < 12; ++i) {
			t = new Option(monthNames[i + 1], i);
			selectElement.options.add(t);
		}
		selectElement.selectedIndex = today.getMonth();
		selects.push(selectElement);
		form.appendChild(selectElement);
	}
	createYearsDropDown = function() {
		var selectElement = document.createElement("SELECT");
		selectElement.name = "year";
		selectElement.id = "year";
		var t;
		var thisYear = today.getFullYear()+100;
		for ( var i = thisYear; i > thisYear - 200; --i) {
			t = new Option(i, i);
			selectElement.options.add(t);
		}
		selectElement.selectedIndex = 100;
		form.appendChild(selectElement);
	}
	createHoursDropDown = function() {
		var selectElement = document.createElement("SELECT");
		selectElement.name = "hours";
		selectElement.id = "hours";
		var t;
		for ( var i = 0; i < 24; ++i) {
			var text = i;
			if (text == 0){
				text = "00";
			} else if (text < 10){
				text = "0" + text;
			}
			t = new Option(text, i);
			selectElement.options.add(t);
		}
		selectElement.selectedIndex = today.getHours();
		selects.push(selectElement);
		form.appendChild(selectElement);
	}
	createMinutesDropDown = function() {
		var selectElement = document.createElement("SELECT");
		selectElement.name = "minutes";
		selectElement.id = "minutes";
		var t;
		for ( var i = 0; i < 60; ++i) {
			var text = i;
			if (text == 0){
				text = "00";
			} else if (text < 10){
				text = "0" + text;
			}
			t = new Option(text, i);
			selectElement.options.add(t);
		}
		selectElement.selectedIndex = today.getMinutes();
		selects.push(selectElement);
		form.appendChild(selectElement);
	}
	createGoButton = function(){
		var btn = document.createElement("BUTTON");
		var t = document.createTextNode("go");
		btn.appendChild(t);
		btn.id = "goDate";
		btn.setAttribute("type","button");
		form.appendChild(btn);
	}
	createNowButton = function(){
		var btn = document.createElement("BUTTON");
		var t = document.createTextNode("now");
		btn.appendChild(t);
		btn.id = "nowDate";
		btn.setAttribute("type","button");
		form.appendChild(btn);
	}

	DateAndTimeDropDowns.prototype.resetDateAndTime = function(date){
		for (var i = selects.length - 1; i >= 0; i--) {
			switch(selects[i].id){
				case "day" :
					selects[i].selectedIndex = date.getDate() - 1;
				break;
				case "month" :
					selects[i].selectedIndex = date.getMonth();
				break;
				case "year" :
					selects[i].selectedIndex = 100;
				break;
				case "hours" :
					selects[i].selectedIndex = date.getHours();
				break;
				case "minutes" :
					selects[i].selectedIndex = date.getMinutes();
				break;
				default :
				break;
			}
			selects[i]
		};
	}
	
	

	window.DateAndTimeDropDowns = DateAndTimeDropDowns;
}(window));